# -*- coding: utf-8 -*-
"""
@Time ： 2023/7/5 22:32
@Auth ： 叶东宇
@File ：TopKFrequentElements.py
"""


class Solution:
    def topKFrequent(self, nums, k):
        dic = {}
        for i in nums:
            if i not in dic:
                dic[i] = 1
            else:
                dic[i] += 1
        reverse_dic = sorted(dic.items(), key=lambda x:x[1], reverse=True)
        li = []
        for i in range(k):
            li.append(reverse_dic[i][0])
        return li

    def topKFrequent_1(self, nums, k):
        from collections import Counter
        dic = Counter(nums)
        reverse_dic = sorted(dic.items(), key=lambda x: x[1], reverse=True)
        li = []
        for i in range(k):
            li.append(reverse_dic[i][0])
        return li




if __name__ == "__main__":
    nums = [1]
    k = 1
    solotion = Solution()
    print(solotion.topKFrequent_1(nums, k))

